//
//  PerfectSelectView.m
//  SHHCPhone
//
//  Created by sheng long on 14-6-18.
//  Copyright (c) 2014年 sheng long. All rights reserved.
//

#import "PerfectSelectView.h"
#import "PSelectView.h"

@interface PerfectSelectView ()<PSelectViewDelegate>
{
    PSelectView *selectView;
    NSArray *dataArray;
}
@end

@implementation PerfectSelectView

@synthesize currentType;
@synthesize viewType;
@synthesize delegate;

-(void)setViewType:(PerfectSelectViewType)type
{
    viewType = type;
    
    NSString *name1 = nil;
    NSString *title1 = nil;
    switch (type) {
        case YQ_TYpe:
        {
            name1 = @"完善资料页-孕期icon.png";
            title1 = @"状态";
            dataArray = [[NSArray alloc] initWithObjects:@[@"完善资料页-孕前.png",@"完善资料页-孕前-选中.png",@"孕前"],@[@"完善资料页-孕中.png",@"完善资料页-孕中-选中.png",@"孕期"],@[@"完善资料页-产后.png",@"完善资料页-产后-选中.png",@"产后"], nil];
        }
            break;
        case YDL_Type:
        {
            name1 = @"完善资料页-运动量icon.png";
            title1 = @"运动强度";
            dataArray = [[NSArray alloc] initWithObjects:@[@"完善资料页-运动量-强.png",@"完善资料页-运动量icon-点击.png",@"轻"],@[@"完善资料页-运动量-中.png",@"完善资料页-运动量-中-点击.png",@"中"],@[@"完善资料页-运动量-弱.png",@"完善资料页-运动量-弱-点击.png",@"重"], nil];
        }
            break;
        default:
            break;
    }
    
    UIImageView *image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:name1]];
    [image1 sizeToFit];
    [self addSubview:image1];
    [image1 setCenter:CGPointMake(10+image1.frame.size.width/2, self.frame.size.height/2)];
    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(36, 12, .5, self.frame.size.height-24)];
    [view1 setBackgroundColor:GET_COLOR(@"f2f2f2")];
    [view1 setAlpha:.6];
    [view1 setBackgroundColor:[UIColor lightGrayColor]];
    [self addSubview:view1];
    
    UILabel *label = [self getLabel:title1];
    [label setCenter:CGPointMake(view1.frame.origin.x+view1.frame.size.width+14+label.frame.size.width/2, view1.center.y)];
    [self addSubview:label];
    
    selectView = [[PSelectView alloc] init];
    [selectView setDelegate:self];
    [selectView setDataArray:dataArray];
    [selectView setCenter:CGPointMake(label.frame.origin.x+label.frame.size.width+5+selectView.frame.size.width/2, view1.center.y)];
    [self addSubview:selectView];
}

-(UILabel*)getLabel:(NSString*)text
{
    UILabel *label1 = [[UILabel alloc] init];
    [label1 setText:text];
    [label1 setTextColor:GET_COLOR(@"ababab")];
    [label1 setBackgroundColor:[UIColor clearColor]];
    [label1 setFont:[UIFont boldSystemFontOfSize:13]];
    [label1 sizeToFit];
    return label1;
}

-(void)setCurrentType:(NSInteger)type
{
    currentType = type;
    selectView.currentType = type;
}

#pragma mark - PSelectViewDelegate
-(void)selectTag:(NSInteger)index
{
    currentType = index;
    CLog(@"%d",index);
    if ([(NSObject*)self.delegate respondsToSelector:@selector(selectIndex:view:)]) {
        [self.delegate selectIndex:index view:self];
    }
}

@end
